﻿namespace IPMS.BLL
{
    using IPMS.DAL;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class ProjectGroupClass
    {
        private string _Applicant;
        private string _Client;
        private string _ClientName;
        private string _Description;
        private DateTime _FirstFilingDate;
        private string _Inventor;
        private string _OfficerEmail;
        private string _OfficerName;
        private string _OfficerRole;
        private string _PCTCountry;
        private DateTime _PCTPriorityDate;
        private DateTime _PriorityDate;
        private string _ProjectClass;
        private string _ProjectGroupID;
        private string _Title;
        private string _TitleSubject;
        private string _Type;
        private bool _IsDelete;

        public void GetPGDefault(string projectGroupId)
        {
            try
            {
                try
                {
                    SqlCommand sqlCmd = new SqlCommand();
                    DataAccessLayer DAL = new DataAccessLayer();
                    DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
                    DAL.AddParamToSQLCmd(sqlCmd, "@ProjectGroupId", SqlDbType.NVarChar, 30, ParameterDirection.Input, projectGroupId);
                    DAL.AddParamToSQLCmd(sqlCmd, "@Client", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
                    DAL.AddParamToSQLCmd(sqlCmd, "@Title", SqlDbType.NVarChar, 60, ParameterDirection.Output, null);
                    DAL.AddParamToSQLCmd(sqlCmd, "@TitleSubject", SqlDbType.NVarChar, 60, ParameterDirection.Output, null);
                    DAL.AddParamToSQLCmd(sqlCmd, "@ProjectClass", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
                    DAL.AddParamToSQLCmd(sqlCmd, "@Applicant", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
                    DAL.AddParamToSQLCmd(sqlCmd, "@Inventor", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
                    DAL.AddParamToSQLCmd(sqlCmd, "@Type", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
                    DAL.AddParamToSQLCmd(sqlCmd, "@IsDelete", SqlDbType.Bit, 1, ParameterDirection.Output, null);
                    DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "GetPGDefaultSp");
                    DAL.ExecuteScalarCmd(sqlCmd);
                    int resultValue = (int) sqlCmd.Parameters["@ReturnValue"].Value;
                    this._Client = (string) sqlCmd.Parameters["@Client"].Value;
                    this._Title = (string) sqlCmd.Parameters["@Title"].Value;
                    this._TitleSubject = (string) sqlCmd.Parameters["@TitleSubject"].Value;
                    this._ProjectClass = (string) sqlCmd.Parameters["@ProjectClass"].Value;
                    this._Applicant = (string) sqlCmd.Parameters["@Applicant"].Value;
                    this._Inventor = (string) sqlCmd.Parameters["@Inventor"].Value;
                    this._Type = (string) sqlCmd.Parameters["@Type"].Value;
                    this._IsDelete = (bool)sqlCmd.Parameters["@IsDelete"].Value;
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
        }

        public int GetProjectGroupInfo(string projectGroupId)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectGroupID", SqlDbType.NVarChar, 30, ParameterDirection.Input, projectGroupId);
            DAL.AddParamToSQLCmd(sqlCmd, "@Description", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@OfficerName", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@OfficerRole", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Title", SqlDbType.NVarChar, 60, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@OfficerEmail", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@FirstFilingDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@PriorityDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectClass", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@PCTCountry", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@PCTPriorityDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Applicant", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Inventor", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Type", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Client", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@TitleSubject", SqlDbType.NVarChar, 60, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ClientName", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@IsDelete", SqlDbType.Bit, 1, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "RetrieveProjectGroupSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            int resultValue = (int) sqlCmd.Parameters["@ReturnValue"].Value;
            this._Description = (string) sqlCmd.Parameters["@Description"].Value;
            this._OfficerName = (string) sqlCmd.Parameters["@OfficerName"].Value;
            this._OfficerRole = (string) sqlCmd.Parameters["@OfficerRole"].Value;
            this._Title = (string) sqlCmd.Parameters["@Title"].Value;
            this._OfficerEmail = (string) sqlCmd.Parameters["@OfficerEmail"].Value;
            this._FirstFilingDate = (DateTime) sqlCmd.Parameters["@FirstFilingDate"].Value;
            this._PriorityDate = (DateTime) sqlCmd.Parameters["@PriorityDate"].Value;
            this._ProjectClass = (string) sqlCmd.Parameters["@ProjectClass"].Value;
            this._PCTCountry = (string) sqlCmd.Parameters["@PCTCountry"].Value;
            this._PCTPriorityDate = (DateTime) sqlCmd.Parameters["@PCTPriorityDate"].Value;
            this._Applicant = (string) sqlCmd.Parameters["@Applicant"].Value;
            this._Inventor = (string) sqlCmd.Parameters["@Inventor"].Value;
            this._Type = (string) sqlCmd.Parameters["@Type"].Value;
            this._Client = (string) sqlCmd.Parameters["@Client"].Value;
            this._TitleSubject = (string) sqlCmd.Parameters["@TitleSubject"].Value;
            this._ClientName = (string) sqlCmd.Parameters["@ClientName"].Value;
            this._IsDelete = (bool)sqlCmd.Parameters["@IsDelete"].Value;

            return resultValue;
        }

        public bool Update(bool IsDelete, string UpdateBy, string UpdateIP, string ProjectGroupID)
        {
            bool isSuccess = false;
            try
            {
                SqlCommand sqlCommand = new SqlCommand();
                DataAccessLayer DAL = new DataAccessLayer();

                string sqlString = "UPDATE [ProjectGroup] SET IsDelete = @IsDelete,UpdateBy = @UpdateBy,UpdateDate = GETDATE(), UpdateIP = @UpdateIP WHERE (([ProjectGroupID] = @Original_ProjectGroupID))";

                DAL.SetCommandType(sqlCommand, CommandType.Text, sqlString);
                DAL.AddParamToSQLCmd(sqlCommand, "@IsDelete", SqlDbType.Bit, 1, ParameterDirection.Input, IsDelete);
                DAL.AddParamToSQLCmd(sqlCommand, "@UpdateBy", SqlDbType.NVarChar, 60, ParameterDirection.Input, UpdateBy);
                DAL.AddParamToSQLCmd(sqlCommand, "@UpdateIP", SqlDbType.NVarChar, 50, ParameterDirection.Input, UpdateIP);
                DAL.AddParamToSQLCmd(sqlCommand, "@Original_ProjectGroupID", SqlDbType.NVarChar, 60, ParameterDirection.Input, ProjectGroupID);
                DAL.ExecuteScalarCmd(sqlCommand);

                isSuccess = true;
            }
            catch { }

            return isSuccess;
        }

        public bool Delete(string ProjectGroupID)
        {
            bool isSuccess = false;
            try
            {
                SqlCommand sqlCommand = new SqlCommand();
                DataAccessLayer DAL = new DataAccessLayer();

                string sqlString = " DELETE FROM [ProjectGroup] WHERE (([ProjectGroupID] = @Original_ProjectGroupID)) ";

                DAL.SetCommandType(sqlCommand, CommandType.Text, sqlString);
                DAL.AddParamToSQLCmd(sqlCommand, "@Original_ProjectGroupID", SqlDbType.NVarChar, 60, ParameterDirection.Input, ProjectGroupID);
                DAL.ExecuteScalarCmd(sqlCommand);

                isSuccess = true;
            }
            catch { }

            return isSuccess;
        }

        public string Applicant
        {
            get
            {
                return this._Applicant;
            }
        }

        public string Client
        {
            get
            {
                return this._Client;
            }
        }

        public string ClientName
        {
            get
            {
                return this._ClientName;
            }
        }

        public string Description
        {
            get
            {
                return this._Description;
            }
        }

        public DateTime FirstFilingDate
        {
            get
            {
                return this._FirstFilingDate;
            }
        }

        public string Inventor
        {
            get
            {
                return this._Inventor;
            }
        }

        public string OfficerEmail
        {
            get
            {
                return this._OfficerEmail;
            }
        }

        public string OfficerName
        {
            get
            {
                return this._OfficerName;
            }
        }

        public string OfficerRole
        {
            get
            {
                return this._OfficerRole;
            }
        }

        public string PCTCountry
        {
            get
            {
                return this._PCTCountry;
            }
        }

        public DateTime PCTPriorityDate
        {
            get
            {
                return this._PCTPriorityDate;
            }
        }

        public DateTime PriorityDate
        {
            get
            {
                return this._PriorityDate;
            }
        }

        public string ProjectClass
        {
            get
            {
                return this._ProjectClass;
            }
        }

        public string Title
        {
            get
            {
                return this._Title;
            }
        }

        public string TitleSubject
        {
            get
            {
                return this._TitleSubject;
            }
        }

        public string Type
        {
            get
            {
                return this._Type;
            }
        }

        public bool IsDelete
        {
            get
            {
                return this._IsDelete;
            }
        }
    }
}

